package com.cayden.base.utils.string;

/**
 * @author cayden
 * @date 2021-10-27 10:48
 */
public class ToString {

    public static String toString(Object[] i) {
        return toString((Object[])i, 50);
    }

    public static String toString(Object[] a, int size) {
        if (a == null) {
            return "null";
        } else {
            int iMax = a.length - 1;
            if (iMax == -1) {
                return "[]";
            } else {
                StringBuilder b = new StringBuilder(10 * Math.min(size, a.length));
                b.append('[');

                for(int i = 0; i < size; ++i) {
                    b.append(String.valueOf(a[i]));
                    if (i == iMax) {
                        return b.append(']').toString();
                    }

                    b.append(",");
                }

                b.append("...]");
                return b.toString();
            }
        }
    }
}
